package fi.profecons.csswindows.toolkit;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import fi.profecons.csswindows.RestrictedContainer;


public class TableRow extends RestrictedContainer {

	public TableRow() {
		super();
		addCommand("new TableRow('" + getId() + "');");
	}

	public TableRow(int cells) {
		addCommand("new TableRow('" + getId() + "');");
		for (int i = 0; i < cells; i++) {
			addCell();
		}
	}

	public List getCells() {
		return getAll();
	}

	public TableCell addCell() {
		TableCell cell = new TableCell();
		addCell(cell);
		return cell;
	}

	public void addCell(TableCell cell) {
		this.add(cell);
		addCommand("getElement('" + getId() + "').addElement(getElement('"
				+ cell.getId() + "'));");
	}
	
	public int numberOfColumns(){
		return getAll().size();
	}
	
	public int getWidth(){
		int width = 0;
		Iterator i = getAll().iterator();
		while(i.hasNext()){
			TableCell cell = (TableCell)i.next();
			width += cell.getWidth();
		}
		return width;
	}
	
	public int getHeight(){
		int height = 0;
		Iterator i = getAll().iterator();
		while(i.hasNext()){
			TableCell cell = (TableCell)i.next();
			if(cell.getHeight() > height)
			height += cell.getHeight();
		}
		return height;
	}
}
